package com.hwhhhh.mygrad.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.hwhhhh.mygrad.R;
import com.hwhhhh.mygrad.dto.MentionDTO;
import com.hwhhhh.mygrad.view.RoundImageView;

import java.util.List;

public class MentionAdapter extends RecyclerView.Adapter<MentionAdapter.MentionHolder> {
    private List<MentionDTO> data;
    private View itemView;

    public MentionAdapter(List<MentionDTO> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public MentionHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mention, parent, false);
        return new MentionHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull MentionHolder holder, int position) {
        MentionDTO mentionDTO = data.get(position);
        Glide.with(holder.itemView).load(mentionDTO.getProfilePhoto()).into(holder.profilePhoto);
        holder.tvName.setText(mentionDTO.getUname());
        holder.tvContent.setText(mentionDTO.getContent());
        String str = "我的回复：" + mentionDTO.getParentContent();
        holder.tvContentParent.setText(str);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    static class MentionHolder extends RecyclerView.ViewHolder {
        private TextView tvName, tvContent, tvContentParent, tvDate;
        private RoundImageView profilePhoto;

        public MentionHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_mention_name);
            tvContent = itemView.findViewById(R.id.tv_mention_content);
            tvContentParent = itemView.findViewById(R.id.tv_mention_parent);
            profilePhoto = itemView.findViewById(R.id.iv_mention_profile_photo);
            tvDate = itemView.findViewById(R.id.tv_mention_date);
        }
    }
}
